package bean;

import lombok.Data;
import lombok.NoArgsConstructor;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Map;
import java.util.TimeZone;

@Data
@NoArgsConstructor
public class FileEntityBean {
    private String uid;
    private String uid_type;
    private int game_id;
    private String day;
    private String agent;
    private String ip;
    private Timestamp timestamp;
    private Timestamp time;
    private String year;
    private String month;
    private String week;
    private String hour;
    private String minute;
    private Map<String,String> properties;

    private String timezone;

    public FileEntityBean( String uid, String uid_type, String agent, String ip, String timestamp, String time, int game_id, String timezone,Map<String,String> properties) {
        this.uid = uid;
        this.uid_type = uid_type;
        this.agent = agent;
        this.ip = ip;
        timestamp = (timestamp+"0000").substring(0,13);
        time = (time+"0000").substring(0,13);
        this.game_id = game_id;
        this.timezone = timezone;
        this.properties=properties;
        setYearMonthWeekDayHourMin(timestamp,time);
    }

    private void setYearMonthWeekDayHourMin(String timestamp, String time) {
        long t = Long.parseLong(timestamp);
        long t2 = Long.parseLong(time);

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
        sdf.setTimeZone(TimeZone.getTimeZone(this.timezone));

        String timestamp2 = sdf.format(t);
        String dateAndTime = sdf.format(t2);

        this.year = dateAndTime.substring(0,4);
        this.month = dateAndTime.substring(0,7);
        this.day = dateAndTime.substring(0,10);
        this.week = day +":"+ dateAndTime.substring(11,13) + getWeekOfMonth(day) ;
        this.hour = dateAndTime.substring(0,13);
        this.minute = dateAndTime.substring(0,16);
        this.timestamp = Timestamp.valueOf(timestamp2);
        this.time = Timestamp.valueOf(dateAndTime);
    }

    private String getWeekOfMonth(String day){
        int num = (Integer.parseInt(day.substring(8, 10))-1)/7+1;
        String weekOfMonth = "";
        switch(num){
            case 1 :
                weekOfMonth="(第一周)";
                break;
            case 2 :
                weekOfMonth="(第二周)";
                break;
            case 3 :
                weekOfMonth="(第三周)";
                break;
            case 4 :
                weekOfMonth="(第四周)";
                break;
            case 5 :
                weekOfMonth="(第五周)";
                break;
        }
        return weekOfMonth;
    }

}
